﻿package org.openChart.display 
{
	import flash.geom.Point;
	import flash.sampler.NewObjectSample;
	import org.openChart.meta.BarChart;
	import org.openChart.meta.ChartType;
	import org.openChart.util.Rectangle;
	/**
	 * The display data model of bar chart.
	 * 
	 * @author Chongyuan
	 */
	public class DisplayBarChart extends DisplayChart implements DisplayInterface
	{
		
		private var xDisplayAxis_:DisplayXAxis;
		private var yDisplayAxis_:DisplayYAxis;
		
		public function DisplayBarChart( chart_:BarChart, parent_:DisplayScreen) 
		{
			super(chart_, parent_);
		}
		
		public override function initialize():void
		{
			var barChart:BarChart = chart as BarChart;
			
			xDisplayAxis_ = new DisplayXAxis(barChart.xAxis, this);
			xDisplayAxis.initialize();
			
			yDisplayAxis_ = new DisplayYAxis(barChart.yAxis, this);
			yDisplayAxis.initialize();
			
			super.initialize();
		}
		
		public override function resize(rectange:Rectangle):void
		{
			this.left = rectange.left;
			this.top = rectange.top;
			this.bottom = rectange.bottom;
			this.right = rectange.right;
			
			var y_offset:Number = yDisplayAxis.title.height + yDisplayAxis.labels.maxWidth + yDisplayAxis.sticks.maxHeight + 10;
			var x_offset:Number = xDisplayAxis.title.height + xDisplayAxis.labels.maxHeight + xDisplayAxis.sticks.maxHeight + 10;
			
			var centerPoint:Point = new Point(this.left + y_offset, bottom - x_offset);
			xDisplayAxis.startPoint = centerPoint;
			yDisplayAxis.startPoint = centerPoint;
			if (this.chartType.indexOf("3d") > 0 && chartType.indexOf("bar") > 0)
			{
				xDisplayAxis.endPoint = new Point(this.right, bottom - x_offset);
				yDisplayAxis.endPoint = new Point(this.left + y_offset, top);
				
			}
			else
			{
				xDisplayAxis.endPoint = new Point(this.right - 15, bottom - x_offset );
				yDisplayAxis.endPoint = new Point(this.left + y_offset, top + 15);
			}
			
			xDisplayAxis.resize(rectange);
			yDisplayAxis.resize(rectange);
			
			super.resize(rectange);
			
			rectange.left += y_offset;
			rectange.bottom -= x_offset;
		}
		
		public function get xDisplayAxis():DisplayXAxis
		{
			return this.xDisplayAxis_;
		}
		
		public function get yDisplayAxis():DisplayYAxis
		{
			return this.yDisplayAxis_;
		}
		
		public override function toString():String
		{
			var str:String = "Object:DisplayBarChart ";
			str += super.toString();
			str += "[x-axis = " + xDisplayAxis + "]";
			str += "[y-axis = " + yDisplayAxis +"]";
			return str;
		}
	}
	
}